package com.xxxx.crm.controller;

import com.xxxx.crm.base.BaseController;
import com.xxxx.crm.base.ResultInfo;
import com.xxxx.crm.query.OrderDetailsQuery;
import com.xxxx.crm.service.OrderDetailsService;
import com.xxxx.crm.vo.CustomerOrder;
import com.xxxx.crm.vo.OrderDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@RequestMapping("order_details")
@Controller
public class OrderDetailsController extends BaseController {

    @Resource
    private OrderDetailsService orderDetailsService;


    /**
     * 分页条件查询订单详情列表
     * @param orderDetailsQuery
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryOrderDetailsByParams(OrderDetailsQuery orderDetailsQuery) {
        return orderDetailsService.queryOrderDetailsByParams(orderDetailsQuery);
    }

    /**
     * 进入添加/修改订单明细页面
     */
    @RequestMapping("toAddOrUpdateOrderDetailsPage")
    public String toAddOrUpdateCustomerOrderPage(Model model, Integer oId, Integer id) {
        // 将客户ID设置到请求域中，给计划项页面获取
        model.addAttribute("oId", oId);
        // 通过计划项ID查询记录
        OrderDetails orderDetails = orderDetailsService.selectByPrimaryKey(id);
        // 将计划项数据设置到请求域中
        model.addAttribute("orderDetails", orderDetails);
        return "customer/orderDetailsAdd_update";
    }


    /**
     * 添加订单明细
     *
     *
     (。_。)
     * @param orderDetails
     * @return com.xxxx.crm.base.ResultInfo
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCustomerOrder(OrderDetails orderDetails) {
        orderDetailsService.addOrderDetails(orderDetails);
        return success("订单明细添加成功！");
    }

    /**
     * 更新订单明细
     *
     *
     (。_。)
     * @param orderDetails
     * @return com.xxxx.crm.base.ResultInfo
     */
//    @PostMapping("update")
//    @ResponseBody
//    public ResultInfo updateCustomerOrder(OrderDetails orderDetails) {
//        orderDetailsService.updateOrderDetails(orderDetails);
//        return success("订单明细更新成功！");
//    }

    /**
     * 删除订单明细
     *
     *
     (。_。)
     * @param id
     * @return com.xxxx.crm.base.ResultInfo
     */
    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteOrderDetails(Integer id) {
        orderDetailsService.deleteOrderDetails(id);
        return success("订单明细删除成功！");
    }
}
